<?php
/*************************************************************************************
 *
 *	FileName: header_php.php
 *	Desc    : Send messages to friends
 *	Author  : Seal
 *	Date    : 2009-12-29
 *
 *************************************************************************************/

if( isset($_POST['action']) && $_POST['action'] == 'send' )
{
	$errmsg = GetMessageStack();
	Process();
}

$friendDAO = GetFriendDAO();
$friends = $friendDAO->GetFriendsNicks( GetLoginUserID() );

	


function Process()
{
	global $errmsg;
	
	if( $errmsg->size('add_review') > 0 )
		return;
	
	$receivers = trim( $_POST['ids'] );
	$title = trim( $_POST['title'] );
	$content = trim( $_POST['content'] );
	
	$receivers_id = edp_db_input( rtrim( $receivers, "," ) );
		
	
	$userDAO = GetUserDAO();
	
	$idNicks = $userDAO->ValidateIDs( edp_db_input($receivers_id) );
				
	
	
	if( count($idNicks) > 0)
	{
		$receivers_id = array();
		$receivers_name = array();
		
		foreach( $idNicks as $key => $value )
		{
			$receivers_id[] = $value['id'];
			$receivers_name[] = $value['nick'];
		}
		
		$letterDAO = GetLetterDAO();
		$letterDAO->SendLetter( $receivers_id, GetLoginUserID(), GetLoginUserName(), 
			edp_db_input($title), edp_db_input($content));
	}
	
	edp_redirect_inner( "mail_inbox", "" );
}
?>